import json
from enum import Enum as Enum

class Datatype(Enum):
    NORMAL   = 1
    BOUNDARY = 2
    INVALID  = 3

class OperationType(Enum):
    CREATE = 1
    READ   = 2
    UPDATE = 3
    DELETE = 4

# class CompType:
#     EQUAL                 = '='
#     NOT_EQUAL             = '!='
#     GREATER_THAN          = '>'
#     LESS_THAN             = '<'
#     GREATER_THAN_OR_EQUAL = '>='
#     LESS_THAN_OR_EQUAL    = '<='

def generate_braces(n) -> str:
    s = "("
    for i in range(n):
        s += "%s"
        if i != n-1:
            s += ", "
    s += ")"
    return s

def generate_insert_sql(table_name, columns):
    placeholders = generate_braces(len(columns))
    sql = f"INSERT INTO {table_name} ({', '.join(columns)}) VALUES {placeholders}"
    return sql

def generate_delete_sql(table_name, where=None):
    sql = f"DELETE FROM {table_name}"
    if where:
        sql += f" WHERE {where}"
    return sql

def generate_select_sql(table_name, columns='*', where=None, limit=None):
    if columns == '*':
        sql = f"SELECT {columns} FROM {table_name}"
    else:
        sql = f"SELECT {', '.join(columns)} FROM {table_name}"
    if where:
        sql += f" WHERE {where}"
    if limit:
        sql += f" LIMIT {limit}"
    return sql

test_insert_data = {
    "record" : {
        "phone_73c280f2783": {
        "dialing_code": "+86",
            "country_code": "CN",
            "number": "15988645343"
        },
        "region_83b49d9a446": {
            "_id": "100"
        },
        "decimal_a446e77c109": "666",
        "number_a33398bfae5": 100,
        "attachment_75204baa676": [
        ],
        "datetime_bfae52d8694": 1750927056368,
        "richText_76d22d35024": {
        },
        "multilingual_24673c280f2": {
            "zh_cn": "2025-07-04创建",
            "en_us": "2025-07-04： Sample text"
        },
        "lookup_6a2675204ba": {
            "_id": "100"
        },
        "date_398bfae52d8": "2025-06-29",
        "subObject_6e77c1097a9": [
            {
                "text_36bb17b5c7d": "Sample text"
            }
        ],
        "option_e52d86948bb": "option_52d86948bb9",
        "text_7ea7d6a3339": "===============",
        "avatar_280f2783b49": {
        },
        "bigint_7d6a33398bf": "888",
        "boolean_e206a267520": 'false',
        "email_f2783b49d9a": "sample_lml@feishu.cn"
    }
}
    
    
# # 1. 建立数据库连接
# connection = pymysql.connect(
#     host='localhost',   # 数据库地址
#     user='lml',  # 数据库用户名
#     password='681020',  # 数据库密码
#     database='helloworld',  # 数据库名
#     charset='utf8mb4',  # 字符集
#     cursorclass=pymysql.cursors.DictCursor  # 结果以字典形式返回
# )

# try:
#     # 2. 创建游标对象
#     with connection.cursor() as cursor:

#         # # === 更新数据（Update） ===
#         # sql_update = "UPDATE users SET age = %s WHERE name = %s"
#         # cursor.execute(sql_update, (26, 'Alice'))
#         # connection.commit()
#         # print("\n更新Alice的年龄成功！")

#         # # === 删除数据（Delete） ===
#         # sql_delete = "DELETE FROM users WHERE name = %s"
#         # cursor.execute(sql_delete, ('Bob',))
#         # connection.commit()
#         # print("删除Bob记录成功！")

# finally:
#     # 3. 关闭数据库连接
#     connection.close()
#     print("\n数据库连接已关闭")

